package com.likan.chqjtgc.fallBackFactory;

import com.likan.chqjtgc.enums.HttpStatus;
import com.likan.chqjtgc.exception.BaseException;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Component;
/**
 * @author : liuxinghong
 * @Description :  统一处理feigin调用异常
 * @date: 2021/1/10 10:58
 **/

@Slf4j
@Component
    public class FeignFallbackFactory implements FallbackFactory<T> {
    @Override
    public T create(Throwable throwable) {
        String msg = throwable == null ? "" : throwable.getMessage();
        if (org.apache.commons.lang3.StringUtils.isNotBlank(msg)) {
            log.error(msg);
        }
        //feign调用失败  抛出异常
        throw new BaseException(HttpStatus.SERVICE_FAILE.value(),HttpStatus.SERVICE_FAILE.msg());
        }
    }

